package com.example.seed.service;

import com.example.seed.aop.LogPoint;
import com.example.seed.entity.Objects;
import com.example.seed.entity.SysLog;
import org.aspectj.lang.ProceedingJoinPoint;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Arrays;

public interface SysLogRepository extends JRepository<SysLog, Long>, LogPoint {

    @Override
    default void add(ProceedingJoinPoint joinPoint, String methodName, String operate) {
        Object[] args = joinPoint.getArgs();
        SysLog sysLog = Objects.createSysLog(draft -> {
            draft.setClassName(joinPoint.getTarget().getClass().getSimpleName());
            draft.setArgs(Arrays.asList(args));
            draft.setMethodName(methodName);
            draft.setOperation(operate);
        });
        save(sysLog);
    }
}
